import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/16 10:42
 * @description 差分数组 再求前缀和
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int minMoves(int[] nums, int limit) {
        // 互补和的范围 最小是2 ，最大是2 * limit
        int[] diff = new int[2 * limit + 2];
        int n  = nums.length;
        for (int i = 0; i < n / 2; i++) {
            int A = nums[i], B = nums[n - i - 1];
            // [2, 2 * limit]之间先设置为2
            int left  = 2, right = 2 * limit;
            diff[left] += 2;
            diff[right + 1] -= 2;

            // [1 + min(A, B), limit + max(A, B)]之间只需要修改一次，那么减去1
            left = 1 + Math.min(A, B);
            right = limit + Math.max(A, B);
            diff[left] += -1;
            diff[right + 1] -= -1;

            // 恰好为A + B，不需要修改，再减去1
            left = A + B;
            right = A + B;
            diff[left] += -1;
            diff[right + 1] -= -1;
        }
        int ans = n, sum = 0;
        for (int i = 2; i <= 2*limit; i++) {
            sum += diff[i];
            if (sum < ans) {
                ans = sum;
            }
        }
        return ans;
    }
}
